import subprocess
# 检测IP是否连通
def checkIP(ip):
    ping_cmd = "ping -n 1 -w 1 %s" % ip
    null = open("win_null", mode="wb")
    ping_result = subprocess.call(ping_cmd, shell=True, stdout=null, stderr=null)
    if ping_result == 0:
        print("Host %s is up" % ip)
# 测试
if __name__ == '__main__':
    for i in range(1,255):
        ip = "10.11.2.%d" % i
        checkIP(ip=ip)